#include <stdio.h>
#include <hipopt/hipopt.h>

int
main (int argc, char *argv[])
{
  Hipopts *options = hopt_init(argv);
  int i;
  
  printf("Hipopts *options = hopt_init(argv);\n");
  
  /* anormal usage, here just for showcase purpose ^^ */
  for (i = 0; i < options->count; i++) {
    printf("options->opts[%d]->name: \"%s\"\n", i, options->opts[i]->name);
    printf("options->opts[%d]->value: \"%s\"\n", i, options->opts[i]->value);
    printf("options->opts[%d]->index: \"%d\"\n", i, options->opts[i]->index);
  }
  printf("options->count => %d\n", options->count);
  printf("options->lastopt => %d\n", options->lastopt);
  
  printf("hopt_isset(\"foo\", options) => %d\n", hopt_isset("foo", options));
  printf("hopt_get(\"foo\", options) => \"%s\"\n", hopt_get("foo", options));
  printf("hopt_indexof(\"foo\", options) => \"%d\"\n", hopt_indexof("foo", options));
  printf("hopt_getn(1, options) => %s\n", hopt_getn(1, options));
  printf("hopt_getn(-1, options) => %s\n", hopt_getn(-1, options));
  printf("hopt_count(options) => %d\n", hopt_count(options));
  printf("hopt_lastopt(options) => %d\n", i = hopt_lastopt(options));
  if (i > 0) printf("argv[hopt_lastopt(options)+1] => \"%s\"\n", argv[i+1]);

  
  if (hopt_isset("if", options) && hopt_isset("then", options) && hopt_isset("fi", options)) {
    int ifidx = hopt_indexof("if", options) + 1;
    int thenidx = hopt_indexof("then", options);
    int fiidx = hopt_indexof("fi", options);
    int i;
    printf("\n\n");
    printf("if (");
    for (i = ifidx; i < thenidx; i++) printf("%s ", argv[i]);
    printf(") {\n  ");
    for (i = thenidx + 1; i < fiidx; i++) printf("%s ", argv[i]);
    printf("\n}\n");
  }
  
  hopt_free(options);
  
  return 0;
}
